package com.m1.tzolkin.model.buildables;

import java.util.Collection;
import java.util.HashSet;

import com.m1.tzolkin.model.board.ITechBoard;
import com.m1.tzolkin.model.exceptions.CannotBuildException;
import com.m1.tzolkin.model.exceptions.NoAvailableSkullException;
import com.m1.tzolkin.model.exceptions.NotEnoughCornException;
import com.m1.tzolkin.model.exceptions.NotEnoughResourceException;

public class ActionBuilding extends AbsActionBuildable implements
		IActionBuilding {
	
	// ATTRIBUTS
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -798778894344195440L;
	private final ActionBuildingTypes type;
	
	// CONSTRUCTEUR
	
	private ActionBuilding(ActionBuildingTypes t) {
		super(t.getCost(), t.getType(), t.getAction());
		type = t;
	}
	
	// REQUETES
	
	public static Collection<IActionBuilding> createAll(int i) {
		Collection<IActionBuilding> buildings = new HashSet<IActionBuilding>();
		ActionBuildingTypes[] val = ActionBuildingTypes.values();
		if (i == 0) {
			for (int j = 0; j < 9; ++j) {
				buildings.add(new ActionBuilding(val[j]));
			}
		} else if (i == 1) {
			for (int j = 9; j < val.length; ++j) {
				buildings.add(new ActionBuilding(val[j]));
			}
		}
		return buildings;
	}
	
	@Override
	public String getName() {
		return type.name();
	}
	
	// COMMANDES

	@Override
	public void buy(ITechBoard b) throws NotEnoughCornException, NotEnoughResourceException, NoAvailableSkullException, CannotBuildException {
		b.build(this);
	}

}
